package com.upf1sh.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.upf1sh.bean.Thingmodel;
import com.upf1sh.mapper.ThingmodelMapper;
import com.upf1sh.service.ThingmodelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
* @author Lenovo
* @description 针对表【thingmodel】的数据库操作Service实现
* @createDate 2025-01-03 17:51:55
*/
@Service
public class ThingmodelServiceImpl extends ServiceImpl<ThingmodelMapper, Thingmodel>
    implements ThingmodelService {

    @Autowired
    private ThingmodelMapper thingmodelMapper;

    private LambdaQueryWrapper<Thingmodel> buildWrapper(Thingmodel thingmodel){
        LambdaQueryWrapper<Thingmodel> lam = new LambdaQueryWrapper<>();
        lam.eq(thingmodel.getName()!=null,Thingmodel::getName, thingmodel.getName());
        lam.eq(thingmodel.getTime()!=null,Thingmodel::getTime, thingmodel.getTime());
        lam.eq(thingmodel.getValue()!=null,Thingmodel::getValue, thingmodel.getValue());
        lam.eq(thingmodel.getDataType()!=null,Thingmodel::getDataType, thingmodel.getDataType());
        lam.eq(thingmodel.getAccessMode()!=null,Thingmodel::getAccessMode, thingmodel.getAccessMode());
        lam.eq(thingmodel.getIdentifier()!=null,Thingmodel::getIdentifier, thingmodel.getIdentifier());
        return  lam;
    }

    @Override
    public List<Thingmodel> getThingmodel(Thingmodel thingmodel) {
        LambdaQueryWrapper<Thingmodel> lam = buildWrapper(thingmodel);
        int i = thingmodel.getPageSize() - 1;
        lam.last("LIMIT "+i+","+thingmodel.getPageNum());

        return thingmodelMapper.selectList(lam);
    }

    @Override
    public IPage<Thingmodel> selectPage(Thingmodel thingmodel) {
        Page<Thingmodel> page = new Page<>(thingmodel.getPageSize(), thingmodel.getPageNum());
         //查询分页结果
        return thingmodelMapper.selectPage(page, null);
    }

    @Override
    public Thingmodel getThingmodelById(int id) {
        return thingmodelMapper.selectById(id);
    }

    @Override
    public int addThingmodel(Thingmodel thingmodel) {
        return thingmodelMapper.insert(thingmodel);
    }

    @Override
    public int updateThingmodel(Thingmodel thingmodel) {
        return thingmodelMapper.updateById(thingmodel);
    }

    @Override
    public int deleteThingmodel(int id) {
        return thingmodelMapper.deleteById(id);
    }
}




